package com.cloud.school.app.config.controller;

import com.cloud.school.app.util.ResponseUtil;
import com.cloud.school.app.util.exception.SystemHandleException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName Controller
 * @Description TODO
 * @Author 36297
 * @Date 2018/12/1 18:29
 * @Version 1.0
 */
@Slf4j
@RestControllerAdvice
public class ControllerAdvice {

    @ExceptionHandler(SystemHandleException.class)
    public ResponseUtil handleException(SystemHandleException e) {
        log.error("请求url:{}, 服务器处理异常", ResThreadLocal.getUrl(), e);
        return ResponseUtil.fail(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResponseUtil handleException(Exception e) {
        log.error("请求url:{}, 服务器处理异常", ResThreadLocal.getUrl(), e);
        return ResponseUtil.fail("服务器处理异常！");
    }

    @ExceptionHandler(Throwable.class)
    public ResponseUtil handleException(Throwable e) {
        log.error("请求url:{}, 服务器处理异常", ResThreadLocal.getUrl(), e);
        return ResponseUtil.fail("服务器处理异常！");
    }
}
